package com.itrencai.d22_xpath;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.junit.Test;

import java.io.File;
import java.util.List;

public class XPathDemo {
    //1.绝对路径：/根元素/子元素/子元素
    @Test
    public  void parse01() throws  Exception{
        //a.创建解析器对象
        SAXReader saxReader=new SAXReader();
        //b.把xml加载成document对象
        Document document =saxReader.read(new File(
                "E:\\javalearn\\opp-app\\oop-app\\src\\com\\itrencai\\d21_dom4j\\Contacts.xml"));
        //c.检索全部的名称
        List<Node> nameNodes=document.selectNodes("/contactList/contact/name");
        for (Node nameNode : nameNodes) {
            Element nameEle=(Element) nameNode;
            System.out.println(nameEle.getTextTrim());
        }
    }
    //2.相对路径
    //3.全文检索
    //4.属性查找
}
